package com.udata.client.view.impl;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.udata.client.service.TiebaExpService;
import com.udata.client.service.TiebaExpServiceAsync;
import com.udata.client.view.TiebaExpView;

public class TiebaExpViewImpl extends Composite implements TiebaExpView {
  private static TiebaExpViewImplUiBinder uiBinder = GWT.create(TiebaExpViewImplUiBinder.class);

  interface TiebaExpViewImplUiBinder extends UiBinder<Widget, TiebaExpViewImpl> {
  }

  TiebaExpServiceAsync instanceService = (TiebaExpServiceAsync) GWT.create(TiebaExpService.class);

  @UiField
  TextBox              categoryTextBox;
  @UiField
  TextBox              pageNumTextBox;
  @UiField
  Button               saveDataButton;

  private Presenter    presenter;
  private String       name;

  public TiebaExpViewImpl() {
    initWidget(uiBinder.createAndBindUi(this));
    saveDataButton.addClickHandler(new ClickHandler() {

      @Override
      public void onClick(ClickEvent event) {
        String category = categoryTextBox.getText();
        Integer pageNum = Integer.valueOf(pageNumTextBox.getText());
        instanceService.saveData(category, pageNum, new AsyncCallback<Boolean>() {

          @Override
          public void onFailure(Throwable caught) {
            GWT.log(caught.getLocalizedMessage());
          }

          @Override
          public void onSuccess(Boolean result) {
            System.out.println("success");

          }
        });

      }
    });
  }

  @Override
  public void setName(String name) {
    this.name = name;
  }

  @Override
  public void setPresenter(Presenter presenter) {
    this.presenter = presenter;
  }

}